/**
 * @param {string} s
 * @return {string[][]}
 */
 var partition = function(s) {
    let results = []
    let path = []
    function loop(index){
        if(path.join("").length === s.length){
            if(isPalindrome(path)){
                results.push([...path])
            }
            return
        }
        if(index === s.length){
            return 
        }
        for(let i=1; i<=s.length - index; i++){
            path.push(s.substr(index, i))
            loop(index + i)
            path.pop()
        }
    }

    loop(0)

    console.log(results)

};

function isPalindrome(arr) {
    for (let index = 0; index < arr.length; index++) {
        const str = arr[index];
        if(str !== str.split('').reverse().join('')){
            return false
        }
    }
    return true
}

partition("aab")